# -*- coding: utf-8 -*-
from PhysicObject import *
DISPLAY_SIZE = (800, 600)

class Triangle(PhysicObject):
    img = load_image('images/triangle_warning.png').convert_alpha()
    #image = pygame.transform.rotate(images, 180)
    #image = load_image('images/spikes_floor.png').convert_alpha()
    #image.set_colorkey((255, 255, 255)) #Elijo que color es transparente

    def __init__(self, world, x, y, restitucion=1.8,angl=90):
        self.angle = angl        
        self.world = world
        bodyDef = box2d.b2BodyDef()
        bodyDef.position = (x, y)
        bodyDef.angle = -self.angle*3.14/180
        bodyDef.userData = self
        self.body = self.world.CreateBody(bodyDef)
        
        self.image = pygame.transform.rotate(self.img, self.angle)       

        ##Triangule
        triangleDef = box2d.b2PolygonDef()
        triangleDef.setVertices( [ (2.4, 0.0), (-2.4, 0.0), (0.0, -4.8) ] ) 
        triangleDef.density = 0.01
        triangleDef.friction = 0.05
        triangleDef.restitution = restitucion
        self.body.CreateShape(triangleDef) 
        #self.body.SetMassFromShapes() 
       
    def draw( self, surface, offset_x=0, offset_y=0 ):
        offset_x = 48 
        offset_y = 24
        
        if self.angle<0:
            offset_x = 0 

            
        pos = self.body.GetPosition()
    

        surface.blit(self.image, (int(pos.x*TILE_SIZE)-offset_x,
                    int(pos.y*TILE_SIZE)-offset_y))
  


    def sleeping( self):
        return self.body.IsSleeping()

    def isAllowSleep(self):
        """Indica si tiene permitido dormirse el objeto"""
        pass

    def destroy( self):
        """Destruye el objeto """
        self.body.DestroyShape (self.shape)
